/*
 * StdGate.java
 * 
 * last update: 16.01.2010 by Stefan Saru
 * 
 * author:	Alec(panovici@elcom.pub.ro)
 * 
 * Obs:
 */


package engine;

import java.util.*;
import java.io.*;
import middle.*;

/**
 * Things all standard gates have
 */
class StdGate {
	Delay3 delay;
	NameSpace parent;
	ModuleInstanceDescription id;
	byte type;
	long lastUpdateTime;

	static final int
	X = BitVector.X,
	Z = BitVector.Z,
	L = 0,
	H = 1;

	/**
	 * The truth tables are ordered so we can use
	 * the type member as an index and pass the table to
	 * Bitvector.genericReduction.
	 */
	public static final int [] truthTables [] =
	{//NInput gates
		BitVector.ands,
		BitVector.nands,
		BitVector.ors,
		BitVector.nors,
		BitVector.xors,
		BitVector.xnors,
		//NOutput gates
		{0, 1, X, X},
		{1, 0, X, X},
		//Enable gates  : index should be ('input' << 2) | 'enable'
		//bufif0:
		{0, Z, L, L,
			1, Z, H, H,
			X, Z, X, X,
			X, Z, X, X
		},
		//bufif1:
		{Z, 0, L, L,
			Z, 1, H, H,
			Z, X, X, X,
			Z, X, X, X
		},
		//notif0
		{1, Z, H, H,
			0, Z, L, L,
			X, Z, X, X,
			X, Z, X, X
		},
		//notif1
		{Z, 1, H, H,
			Z, 0, L, L,
			Z, X, X, X,
			Z, X, X, X
		},
		//(r)cmos
		null,
		//nmos
		{Z, 0, L, L,
			Z, 1, H, H,
			Z, X, X, X,
			Z, Z, Z, Z
		},
		//pmos
		{0, Z, L, L,
			1, Z, H, H,
			X, Z, X, X,
			Z, Z, Z, Z
		},
		//rcmos
		null,
		//rnmos
		{Z, 0, L, L,
			Z, 1, H, H,
			Z, X, X, X,
			Z, Z, Z, Z
		},
		//rpmos
		{0, Z, L, L,
			1, Z, H, H,
			X, Z, X, X,
			Z, Z, Z, Z
		}
	};

	StdGate(NameSpace parent, Delay3 delay, byte type,
			ModuleInstanceDescription id) {
		this.delay = delay;
		this.parent = parent;
		this.id = id;
		this.type = type;
		lastUpdateTime = -1;
	}

	public String toString() {
		return parent + "." + id.name;
	}
}


